﻿using System.Data;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using OpenXmlEasy.Basic;
using OpenXmlEasy.Common;
using A = DocumentFormat.OpenXml.Drawing;
using C = DocumentFormat.OpenXml.Drawing.Charts;
using Wp = DocumentFormat.OpenXml.Drawing.Wordprocessing;

namespace OpenXmlEasy.Word
{
    public partial class WordEasy
    {

        public void InsertChart(ChartType chartType, DataColumn categoryColumn, params int[] seriesColumnIndexs)
        {
            var chartId = IdGenerator.Get();
            var chartPart = _doc.MainDocumentPart.AddNewPart<ChartPart>(chartId);

            chartPart.GenerateChartSpace(chartType, categoryColumn, seriesColumnIndexs);

            var paragraph = new Paragraph { RsidParagraphAddition = "005F46E8", RsidParagraphProperties = "005F46E8", RsidRunAdditionDefault = "005F46E8" };

            var paragraphProperties = new ParagraphProperties();
            {
                var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
                paragraphProperties.AppendChild(paragraphMarkRunProperties);
            }
            var justification = new Justification { Val = JustificationValues.Center };
            paragraphProperties.AppendChild(justification);

            var run = new Run();
            {
                var runProperties1 = new RunProperties();

                var drawing1 = new Drawing();

                var inline1 = new Wp.Inline { DistanceFromTop = 0U, DistanceFromBottom = 0U, DistanceFromLeft = 0U, DistanceFromRight = 0U };
                var extent1 = new Wp.Extent { Cx = 5274310L, Cy = 3076575L };
                var effectExtent1 = new Wp.EffectExtent { LeftEdge = 0L, TopEdge = 0L, RightEdge = 21590L, BottomEdge = 9525L };
                var docProperties1 = new Wp.DocProperties { Id = 1U, Name = "图表 1" };
                var nonVisualGraphicFrameDrawingProperties1 = new Wp.NonVisualGraphicFrameDrawingProperties();

                var graphic1 = new A.Graphic();
                graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

                var graphicData1 = new A.GraphicData { Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart" };

                var chartReference1 = new C.ChartReference { Id = chartId };
                chartReference1.AddNamespaceDeclaration("c", "http://schemas.openxmlformats.org/drawingml/2006/chart");
                chartReference1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");

                graphicData1.AppendChild(chartReference1);

                graphic1.AppendChild(graphicData1);

                inline1.AppendChild(extent1);
                inline1.AppendChild(effectExtent1);
                inline1.AppendChild(docProperties1);
                inline1.AppendChild(nonVisualGraphicFrameDrawingProperties1);
                inline1.AppendChild(graphic1);

                drawing1.AppendChild(inline1);

                run.AppendChild(runProperties1);
                run.AppendChild(drawing1);
            }
            paragraph.AppendChild(paragraphProperties);
            paragraph.AppendChild(run);
            _body.AppendChild(paragraph);
        }

        public void InsertLine(DataColumn categoryColumn, DataColumn[] dataColumns, string yAxisTitle)
        {

        }
    }
}
